<template>
    <h1>权益显示</h1>
    <div>
        <table border="1">
            <thead>
                <tr>
                    <th>权益名称</th>
                    <th>描述</th>
                    <th>状态</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="h in data">
                    <th>{{ h.RightName }}</th>
                    <th>{{ h.RightDes }}</th>
                    <th>{{ h.RightState?"启用":"禁用" }}</th>
                    <th>
                        <input type="button" :value="h.RightState?'禁用':'启用'" @click="UpdateRightState(h.RightId)">
                    </th>
                    <th>
                        <input type="button" value="删除" @click="DelRight(h.RightId)">
                    </th>
                    <th>
                        <input type="button" value="编辑" @click="UpdateRight(h.RightId)">
                    </th>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { reactive, ref, renderSlot } from 'vue';
import { useRouter } from 'vue-router';
import { onMounted } from 'vue';
import { useRoute } from 'vue-router';
const data=ref([{
    "RightId": 0,
  "RightName": "",
  "RightDes": "",
  "RightState": true,
  "RightDelete": true
}])

onMounted(()=>{
    Show();
})

const Show=()=>{
    axios.get("https://localhost:7147/api/Member/ShowRight",{params:data.value}).then(res=>{
        data.value=res.data;
    })
}


const UpdateRightState=(val:any)=>{
    if(confirm('确定修改状态吗?')){
        axios.get("https://localhost:7147/api/Member/UpdateRightState",{params:{RightId:val}}).then(res=>{
        if(res.data>0){
            alert('修改权益状态成功')
            Show();
        }
        else{
            alert('失败')
        }
    })
    }
    
}


const DelRight=(val:any)=>{
    if(confirm('确定删除吗?')){
        axios.delete("https://localhost:7147/api/Member/DelRight",{params:{RightId:val}}).then(res=>{
        if(res.data>0){
            alert('删除成功')
            Show();
        }
        else{
            alert('失败')
        }
    })
    }
     
}

const routerr=useRouter();

const UpdateRight=(val:any)=>{
    routerr.push({path:'/DetailRightView',query:{RightId:val}})
}




</script>
